#include "filter.h"
#include <math.h>

class GammaTone : public Filter {
 public:
  GammaTone(double frequency, int channel) {
    f_ = frequency;
    channel_ = channel;
    b_ = 1.019*ERB(f_);
  }
  bool Init(int sample_rate, int num_channels) {
    s_rate_ = sample_rate;
  }
  double Value(int offset, int channel) {
    if (channel_ != channel)
      return 0;
    double t = static_cast<double>(offset)/s_rate_;
    return pow(t,n_)*exp(-2*PI*b_*t)*cos(2*PI*f_*t);
  }
  int NumSamples() {
    return static_cast<int>(80000.0/b_);
  }
 private:
  double ERB(double x) {
    return (24.7*(4.37*(x)/1000.0 + 1.0));
  }
  const static double PI = 3.141592658;
  const static double EARQ = 9.26449;
  const static double n_ = 3.0;
  double b_;
  double f_;
  int channel_;
  int s_rate_;
};
